<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page isELIgnored="false" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>用户添加</title>

    <link type="text/css" rel="stylesheet" href="/css/bootstrap.css">
    <link href="/css/admin/materialdesignicons.min.css" rel="stylesheet">
    <link href="/css/admin/style.min.css" rel="stylesheet">

    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="/js/layer.js"></script>
    <script type="text/javascript" src="https://daily-project.oss-cn-guangzhou.aliyuncs.com/bookmall/js/validate.form.js"></script>
</head>
<body>
<div class="container-fluid">
    <form class="site-form" method="post" id="userInsertForm">

        <input type="hidden" name="id" id="id" />

        <div class="form-group">
            <label for="userName">用户名</label>
            <input type="text" class="form-control" name="userName" id="userName" required="required"
                   autocomplete="off">
            <small class="form-text" id="userNameTip">请保证您填写的用户名符合规则。</small>
        </div>

        <div class="form-group">
            <label for="userName">密码</label>
            <input type="password" class="form-control" name="password" id="password" required="required"
                   autocomplete="off">
            <small class="form-text" id="passwordTip">如果不输入,则默认密码为"您输入的用户名+123"，如用户名为"test"，密码为”test123“</small>
        </div>

        <div class="form-group">
            <label for="example-select">角色</label>
            <select class="form-control" id="roleId" name="roleId" size="1">
                <option value="">请选择</option>
                <option value="1">管理员</option>
                <option value="2">普通用户</option>
            </select>
            <small class="form-text">如果不选择，则默认为”普通用户“</small>
        </div>

        <div class="form-group">
            <label for="realName">真实姓名</label>
            <input type="text" class="form-control" name="realName" id="realName" required="required"
                   autocomplete="off">
            <small class="form-text" id="realNameTip">请保证您填写的姓名是真实可靠的。</small>
        </div>

        <div class="form-group">
            <label for="phone">手机号</label>
            <input type="text" class="form-control" name="phone" id="phone" placeholder="请输入正确的手机号" required="required"
                   autocomplete="off">
            <small class="form-text" id="phoneTip">请保证您填写的手机号是正确可使用的。</small>
        </div>

        <div class="form-group">
            <label for="address">收货地址</label>
            <textarea class="form-control" name="address" id="address" rows="2" required="required"
                      autocomplete="off"></textarea>
            <small class="form-text" id="addressTip">请保证您填写的地址准确且详细。</small>
        </div>

        <div class="modal-footer">
            <button type="reset" class="btn btn-default">重置</button>
            <button type="button" class="btn btn-primary" onclick="addUser()">保存</button>
        </div>
    </form>
</div>
<script>
    function addUser() {

        if (validateUserInsert()) {
            $.post("/bookmall/admin/user/insert", $("#userInsertForm").serializeArray(), function (res) {
                if (res) {
                    layer.msg("信息添加成功~", {time: 1000}, function () {
                        document.getElementById("userInsertForm").reset();
                        window.parent.parent.document.getElementById("multitabs_users").contentWindow.location.reload(true);
                    });
                } else {
                    layer.msg("信息添加失败！请确认信息是否完整或联系管理员!", {time: 1500}, function () {
                        document.getElementById("userInsertForm").reset();
                        window.parent.parent.document.getElementById("multitabs_users").contentWindow.location.reload(true);
                    });
                }
            });
        } else {
            layer.msg("请确认信息是否完整后再次提交！", {icon: 2}, function () {

            });
        }
    }
</script>
</body>
</html>
